package com.Crawlzongheng;

import java.util.List;

import com.Model.CrawlListInfo;
import com.zonghengdb.ZongHengDB;

public class CrawlStart {
	private static boolean booleanCrawlList =false;
	private static boolean booleanCrawlIntro =false;
	private static boolean booleanCrawlRead =false;
	private static int crawlinfoThreadNum = 2;
	private static int crawlReadThreadNum = 10;
	
	public void startCrawlList(){
		if(booleanCrawlList){
			return;
		}
		booleanCrawlList = true;
		ZongHengDB db = new ZongHengDB();
		List<CrawlListInfo> infos = db.getCrawlListInfos();
		if(infos == null){
			return;
		}
		for(CrawlListInfo info : infos){
			if(info.getUrl() == null || "".equals(info.getUrl())){
				continue;
			}
			UpdateListThread thread = new UpdateListThread(info.getInfo(), info.getUrl(), Integer.parseInt(info.getFrequency()));
			thread.start();
		}
	}
	
	public void startCrawlIntro(){
		if(booleanCrawlIntro){
			return;
		}
		booleanCrawlIntro= true;
		for(int i = 0;i<crawlinfoThreadNum;i++){
			IntroPageThread thread = new IntroPageThread("novel info page"+i);
			thread.start();
		}
		
	}
	public void startCrawlRead(){
		if(booleanCrawlRead){
			return ;
		}
		booleanCrawlRead=true;
		for(int i =0;i<crawlReadThreadNum;i++){
			ReadPageThread thread = new ReadPageThread("novel read page");
			thread.start();
		}
	}
	
	
	
	public static void main(String[] args) {
		CrawlStart crawlStart = new CrawlStart();
		crawlStart.startCrawlList();
		crawlStart.startCrawlIntro();
		crawlStart.startCrawlRead();
	}
}
